﻿using System.Data;
using System.Data.SqlClient;

namespace _EF扩展方法
{
    public static class BaseContextExtendMethod
    {
        public static int ExtendSqlMethod(this BaseContext db, string strSql, CommandType type, params SqlParameter[] param)
        {
            int result = 0;
            using (SqlConnection conn = new SqlConnection(db.Database.Connection.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.CommandText = strSql;
                    cmd.CommandType = type;
                    cmd.Parameters.AddRange(param);
                    result = cmd.ExecuteNonQuery();
                }
            }
            return result;
        }
    }
}
